package com.manage.platform.controller;

import com.manage.platform.dto.RoleAllocateMenuDto;
import com.manage.platform.dto.RoleDto;
import com.manage.platform.dto.query.RolePageQuery;
import com.manage.platform.service.impl.RoleServiceImpl;
import com.manage.platform.utils.R;
import com.manage.platform.utils.RPage;
import com.manage.platform.vo.MenuTreeVo;
import com.manage.platform.vo.RoleVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * YWD
 * 2025/9/19
 */
@AllArgsConstructor
@RestController
@RequestMapping("/role")
@Tag(name = "系统设置-角色管理")
public class RoleController {

    private final RoleServiceImpl roleServiceImpl;

    /**
     * 查询角色列表
     */
    @PostMapping("/getRolePage")
    @Operation(summary = "查询角色列表(分页)")
    public R<RPage<List<RoleVo>>> getRolePage(@RequestBody RolePageQuery query){
        return R.ok(roleServiceImpl.getRolePage(query));
    }
    /**
     * 查询角色详情
     */
    @GetMapping("/getRoleDetails/{id}")
    @Operation(summary = "查询角色详情")
    public R<RoleVo> getRoleDetails(@Schema(description = "角色ID") @PathVariable("id") Long id){
        return R.ok(roleServiceImpl.getRoleDetails(id));
    }
    /**
     *添加角色
     */
    @PostMapping("/saveRole")
    @Operation(summary = "添加角色")
    public R<Boolean> saveRole(@RequestBody RoleDto dto){
        return R.ok(roleServiceImpl.saveRole(dto));
    }
    /**
     *修改角色
     */
    @PutMapping("/updateRole")
    @Operation(summary = "修改角色")
    public R<Boolean> updateRole(@RequestBody RoleDto dto){
        return R.ok(roleServiceImpl.updateRole(dto));
    }
    /**
     *删除角色
     */
    @DeleteMapping("/deleteRole/{id}")
    @Operation(summary = "删除角色")
    public R<Boolean> deleteRole(@Schema(description = "角色ID") @PathVariable("id") Long id){
        return R.ok(roleServiceImpl.deleteRole(id));
    }
    /**
     * 为角色分配菜单
     */
    @PostMapping("/allocateMenu")
    @Operation(summary = "为角色分配菜单")
    public R<Boolean> allocateMenu(@RequestBody RoleAllocateMenuDto dto){
        return R.ok(roleServiceImpl.allocateMenu(dto));
    }
    /**
     * 查询角色详情
     */
    @GetMapping("/getRoleMenu/{id}")
    @Operation(summary = "查询角色菜单(树形菜单)")
    public R<List<MenuTreeVo>> getRoleMenu(@Schema(description = "角色ID") @PathVariable("id") Long id){
        return R.ok(roleServiceImpl.getRoleMenu(id));
    }

}
